package com.zheng.study.base.bean.search.page;

import com.zheng.study.base.bean.search.SearchEnum;
import com.zheng.study.base.bean.search.projection.Projection;
import com.zheng.study.base.bean.search.projection.ProjectionHelp;
import org.springframework.util.Assert;

/**
 * 查询 - 参数 - PageUnique
 * ============================================================================
 * author : fallenpanda
 * createDate:  2018/6/11 。
 * ============================================================================
 */
public class PageUnique extends Page {

	protected PageUnique(SearchEnum.ResultType resultType, Projection projection) {
		super(resultType, projection);
	}

	public static PageUnique uniqueResult(){
		return newBuilder().setResultType(SearchEnum.ResultType.uniqueResult).setProjection(ProjectionHelp.none()).build();
	}

	public static PageUnique uniqueResult(Projection projection){
		return newBuilder().setResultType(SearchEnum.ResultType.uniqueResult).setProjection(projection).build();
	}

	public static Builder newBuilder(){
		return new Builder();
	}

	public static class Builder extends Page.Builder<Page, Builder>{

		@Override
		protected Builder getThis() {
			return this;
		}

		@Override
		public PageUnique build() {
			Assert.notNull(resultType, "resultType 不能为空");
			Assert.notNull(projection, "projection 不能为空");
			return new PageUnique(resultType, projection);
		}
	}

}
